<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>操作题管理</title>
</head>
<body>

    <div id="mm_20200606" class="easyui-menu" style="width:120px;display: none;">
        <div data-options="iconCls:'icon-add',id:'m-add-20200606'">新增</div>
        <div data-options="id:'m-downLoad-20210128'">下载</div>
        <div data-options="id:'m-delete-20200606'">停用</div>
    </div>

<!--    <div id="toolbar20210125">-->
<!--        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>-->
<!--        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">停用</a>-->
<!--    </div>-->

    <div class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false">
             <table id="dg_20200606"></table>
        </div>
    </div>

    <div id="dialog_20200606_addOrUpdateOrMenu" style="padding:10px 30px;display: none;">
        <form id="logg20200605" method="post" data-options="novalidate:true" enctype="multipart/form-data" >
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="titleType"  data-options="label:'考题类型:',panelHeight:'auto',required:true">
                    <option value="wps" selected>wps</option>
                    <option value="wpp">wpp</option>
                    <option value="et">et</option>
                    <option value="linux">linux</option>
                </select>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="summary" style="width:100%" data-options="label:'考题描述:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-filebox" id="fileZipTem" name="fileZipTem" style="width:100%" data-options="label:'考题上传:',buttonText:'选择压缩包',accept: '.zip',required:true">
            </div>
        </form>
    </div>
    <div id="dialog_button_20200606" style="display: none;">
        <a id="dialog_20200624_addOrUpdateOrMenu_close" >放弃</a>
        <a href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="submitForm20200606()">保存</a>
    </div>

<script>

    function submitForm20200606(){
        let fileSize = $("#fileZipTem").filebox("files")[0];
        if(fileSize.size > 16384000){
            $.messager.alert('提示','上传的图片不能大于16M！！');
            return false;
        }
        $.messager.progress({
            title:'Please waiting',
            msg:'数据保存中，请稍后...'
        });

        $('#logg20200605').form('submit',{
            iframe:false,
            url:'./../fileDepot/mergeFileDepot',
            onSubmit:function(){
                return $(this).form('enableValidation').form('validate');
            },
            onProgress:function (percent){
                console.log(percent)
            },
            success:function(json){
                $.messager.progress('close');
                let data = eval('(' + json + ')');
                if(data.code == 200){
                    new jBox('Notice', {
                        color: 'green',
                        autoClose: 2500,
                        content: '保存成功。',
                        showCountdown: true,
                        animation: 'slide'
                    });
                    reloadDatagridlbgg();
                }else{
                    new jBox('Notice', {
                        color: 'red',
                        autoClose: 2500,
                        content: '保存失败！',
                        showCountdown: true,
                        animation: 'slide'
                    });
                }
            }
        });
    }
    $(function(){
        $('#dialog_20200624_addOrUpdateOrMenu_close').linkbutton({
            onClick: function (none) {
                $('#dialog_20200606_addOrUpdateOrMenu').dialog('close');
            }
        });


        $('#dialog_20200606_addOrUpdateOrMenu').dialog({
            width: '50%',
            closed: true,
            modal: true,
            title: '添加',
            buttons:'#dialog_button_20200606'
        });

        //var text = $('#btn').linkbutton("options").text;

        //鼠标右击菜单
        $('#mm_20200606').menu({
            onClick:function(item){
                let menuTitle = item.text;
                if(item.id == 'm-add-20200606'){
                    $('#dialog_20200606_addOrUpdateOrMenu').dialog('open').dialog('center').dialog('setTitle',menuTitle);
                }
                if(item.id == 'm-delete-20200606'){
                    let id = $('#dg_20200606').datagrid('getSelected');
                    if(id){
                        $.messager.confirm('提示','确定要停用吗?停用后将不在抽题范围内！',function(r){
                            if (r){
                                let rowData = $('#dg_20200606').datagrid('getSelected');
                                let id = rowData.id;
                                deleteDatagridlbgg(id);
                            }
                        });
                    }else{
                        $.messager.alert('提示','请选中一行在操作！');
                    }
                }
                if(item.id == 'm-downLoad-20210128'){
                    let rowData = $('#dg_20200606').datagrid('getSelected');
                    if(rowData){
                        let id = rowData.id;
                        location.href='./../fileDepot/download?id='+id+'&fileName='+rowData.fileName;
                    }else{
                        $.messager.alert('提示','请选中一行在操作！');
                    }
                }
            }
        });

        $('#dg_20200606').datagrid({
            url: './../fileDepot/fileDepotPage',
            method: 'get',
            border: false,
            fit: true,
            fitColumns: true,
            scrollbarSize: 2, //滚动条宽度
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: true,
            sortName: 'id',   //定义排序的列名
            sortOrder: 'desc',   //'asc' 或 'desc'。
            nowrap:false, //设置为 true，则把数据显示在一行里。设置为 true 可提高加载性能。
            columns:[[
                {field:'titleType',title:'类型',width:100},
                {field:'createTime',title:'创建时间',width:100},
                {field:'summary',title:'描述',width:200},
                {field:'fileName',title:'文件名称',width:100},
                {field:'author',title:'添加人',width:100,hidden:true},
                {field:'fileSize',title:'文件大小',width:100,hidden:true,
                    formatter: function(value,row,index){
                            return sizeTostr(value);
                    }
                },
                {field:'state',title:'状态',width:100,
                    formatter: function(value,row,index){
                        if (value == 1){
                            return '<span class="easyui-dot easyui-status-processing"></span> 正常';
                        } else {
                            return '<span class="easyui-dot easyui-status-error"></span> 停用';
                        }
                    }
                }
            ]],
           // toolbar:'#toolbar20210125',
            onHeaderContextMenu: function(e, field){
                e.preventDefault();
                $(this).datagrid('columnMenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
            onRowContextMenu: function(e,index,row) {
                e.preventDefault();
                $(this).datagrid('unselectAll');

                let downLoad = $('#m-downLoad-20210128')[0];
                let del = $('#m-delete-20200606')[0];
                if(!row){
                    $('#mm_20200606').menu('hideItem', downLoad).menu('hideItem', del);
                }else{
                    $('#mm_20200606').menu('showItem', downLoad).menu('showItem', del);
                    $(this).datagrid('selectRow', index);
                }

                $('#mm_20200606').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
        })
    });
    function sizeTostr(size) {
        let data = "";
        if (size < 0.1 * 1024) { //如果小于0.1KB转化成B
            data = size.toFixed(2) + "B";
        } else if (size < 0.1 * 1024 * 1024) {//如果小于0.1MB转化成KB
            data = (size / 1024).toFixed(2) + "KB";
        } else if (size < 0.1 * 1024 * 1024 * 1024) { //如果小于0.1GB转化成MB
            data = (size / (1024 * 1024)).toFixed(2) + "MB";
        } else { //其他转化成GB
            data = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB";
        }
        let sizestr = data + "";
        let len = sizestr.indexOf("\.");
        let dec = sizestr.substr(len + 1, 2);
        if (dec == "00") {//当小数点后为00时 去掉小数部分
            return sizestr.substring(0, len) + sizestr.substr(len + 3, 2);
        }
        return sizestr;
    }

    //设备发布中的信息-逻辑删除
    function deleteDatagridlbgg(id){
        $.ajax({
            type: "POST",
            url: "./../fileDepot/deleteFileDepot",
            data: {id:id},
            success: function(json){
                if(json.code == 200){
                    new jBox('Notice', {
                        color: 'green',
                        autoClose: 2500,
                        content: '操作成功。',
                        showCountdown: true,
                        animation: 'slide'
                    });
                    reloadDatagridlbgg();
                }else{
                    new jBox('Notice', {
                        color: 'red',
                        autoClose: 2500,
                        content: '操作失败！',
                        showCountdown: true,
                        animation: 'slide'
                    });
                }
            }
        });
    }


    //刷新datagrid
    function reloadDatagridlbgg(){
        $('#dialog_20200606_addOrUpdateOrMenu').dialog('close');
        $('#dg_20200606').datagrid('reload');
        $('#logg20200605').form('clear');
    }
</script>
</body>
</html>